<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label">处置部门：</label>
                                    <div class="layui-input-inline">
                                        <input id="departmentSearchClaimId" name="departmentSearchClaimId"
                                               type="hidden"/>
                                        <div id="departmentSearchClaim"></div>
                                    </div>
                                </div>
                                <!-- 责任岗位 -->
                                <div class="layui-inline">
                                    <label class="layui-form-label">责任岗位：</label>
                                    <div class="layui-input-inline">
                                        <select id='reviewPostId' name="reviewPostId"
                                                lay-filter="reviewPostId"
                                                class="common-select-search">
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">产品类别：</label>
                                    <div class="layui-input-inline">
                                        <input id="productTypeId" type="hidden" name="productTypeId">
                                        <div id="productType"></div>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">订单状态：</label>
                                    <div class="layui-input-inline">
                                        <select name="orderStatus" lay-filter="orderStatus"
                                                class="common-select-search">
                                            <option value="">请选择状态</option>
                                            <option value="0">待评审</option>
                                            <option value="1">已评审</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">客户名称：</label>
                                    <div class="layui-input-inline">
                                        <input name="customerId" id="customerId" class="layui-input" type="text"
                                               placeholder="客户名称" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">客户产品SKU料号：</label>
                                    <div class="layui-input-inline">
                                        <input name="customerSku" id="customerSku" class="layui-input" type="text"
                                               placeholder="请输入SKU料号" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">销售订单编码：</label>
                                    <div class="layui-input-inline">
                                        <input name="orderId" id="orderId" class="layui-input" type="text"
                                               placeholder="请输入订单编码" autocomplete="off"/>
                                    </div>
                                </div>
                            </div>
                            <div class="query-rt">
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog"
                                            lay-submit layui-form-keyDownSearch="true">查询
                                    </button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>
                                        重置
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="lay-btn-rows">
                    <div class="lay-btn-box">
                        <div class="lay-btn-lt">
                            <button id="reviewRecordAdd" class="layui-btn icon-btn color-reseda">添加评审记录</button>
                        </div>
                        <div class="lay-btn-rt">

                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="reviewTableInfo" lay-filter="reviewTableInfo"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="reviewRecordTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form','table', 'laydate', 'admin' ,'laytpl','tableTreeDj', 'config'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;


        // 渲染表格
        var insTb = table.render({
            elem: '#reviewTableInfo',
            url: config.base + 'enterprise/product/admin/productRecordReview/list?processId=1',
            toolbar: true,
            defaultToolbar: ["filter"],
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号', fixed: 'left'}
                ,{field: 'no', align:'center', title: '评审任务编号',width: 175, fixed: 'left'}
                ,{field: 'orderNo', align:'center', title: '评审订单编号',width: 165}
                ,{field: 'cusSkuCode', align:'center', title: '客户SKU料号'}
                ,{field: 'cusProductCode', align:'center', title: '客户产品编号'}
                ,{field: 'cusProductSpec', align:'center', title: '规格码'}
                ,{field: 'productTypeName', align:'center', title: '所属类别'}
                ,{field: 'customerName', align:'center', title: '所属客户'}
                ,{field: 'result', align:'center', title: '评审结果'}
                ,{field: 'reviewerName', align:'center', title: '评审人'}
                ,{field: 'reviewOkTime', align:'center', title: '评审时间',width: 160}
                ,{toolbar: '#reviewRecordTableBar', title: '操作', width: 150, fixed: 'right'}
            ]],
            done: function (res, curr, count) {
                //移除按钮
                var menuButton = config.getMenuButton(location.hash);
                if(menuButton.indexOf("搜索") == -1){
                    $('.layui-form.toolbar').remove();
                }
                if(menuButton.indexOf("修改") == -1){
                    $("[lay-event='edit']").remove();
                }
                if(menuButton.indexOf("删除") == -1){
                    $("[lay-event='del']").remove();
                }
            }
        });

        //初始化产品类别
        admin.initDataSelectTree(true, 'enterprise/product/admin/productType/getTreeData', {limit: 99999}, "productType", null, "产品类别", "productTypeId", function (row) {
            $("input[name='productTypeId']").val(row.arr[0].value)
        });

        //部门列表
        admin.initDataSelectTree(true, 'user/admin/role/getTreeData', null, 'departmentSearchClaim', null, "部门", "departmentSearchClaimId", function (data) {
            // 获取部门ID
            let departmentId = data.change[0].value;
            //赋值部门id
            $('#departmentSearchClaimId').val(data.change[0].value);
            $('#reviewPostId').empty();
            //部门下的岗位列表
            admin.initDataSelect("user/admin/role/getPostData", {roleId: departmentId}, "reviewPostId", null, "岗位", null, null);
        });

        //渲染下拉
        form.render('select');

        // 工具条点击事件
        table.on('tool(reviewTableInfo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') { //修改
                showEditModel(data);
            }else if(obj.event === 'detail') { //详情
                showDetailModel(data, "1");
            }
        });



        //监听排序
        table.on('sort(reviewTableInfo)', function(obj){
            table.reload('reviewTableInfo', {
                initSort: obj
                ,where: {
                    sort: obj.field
                    ,order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            console.log("data",data);
            insTb.reload({where: data.field,page: {curr: 1}},'data');
        });

        // 重置搜索
        form.on('submit(resets)', data => {
            insTb.reload({where: admin.resetSearch(data.field), page: {curr: 1}}, 'data');
        });

        // 添加按钮点击事件
        $('#reviewRecordAdd').click(function () {
            showEditModel();
        });

        // 显示编辑弹窗
        function showEditModel(data) {
            let title = "添加评审任务";
            admin.formOpen({
                type: 1,
                area: ['1380px', '90%'],
                style: 'font-size: 20px;',
                title: title,
                path: 'components/product/productReview_add_from.html',
                finish: function (){
                    table.reload('reviewTableInfo',{});
                }
            });
        }

        //显示详情
        function showDetailModel(data,pageName) {
            //1.详情 2.审核页面
            data.pageName = pageName;
            admin.putTempData("reviewData", data ? data : null);
            admin.formOpen({
                type: 1,
                area: ['1380px', '90%'],
                style: 'font-size: 20px;',
                title: "评审任务详情",
                path: 'components/product/productReview_detail_from.html',
                finish: function (){
                    table.reload('reviewTableInfo',{});
                }
            });
        }
    });
</script>